/*----------------------------------------------------------------------------

	Copyright (c) 2006, Creator of the Cant Project.
	All rights reserved.

	Redistribution and use in source and binary forms, with or without
	modification, are permitted provided that the following conditions are met:

	+ Redistributions of source code must retain the above copyright notice,
	this list of conditions and the following disclaimer.

	+ Redistributions in binary form must reproduce the above copyright notice,
	this list of conditions and the following disclaimer in the documentation
	and/or other materials provided with the distribution.

	+ Neither the name of the Creator of the Cant Project nor the names of its
	contributors may be used to endorse or promote products derived from this
	software without specific prior written permission.

	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
	AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
	ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
	LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
	CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
	POSSIBILITY OF SUCH DAMAGE.

----------------------------------------------------------------------------*/

#ifndef	_TESTCASE_HPP_
#define	_TESTCASE_HPP_

#include	<string>
#include	<vector>

#include	"../base/exception.hpp"
#include	"../util/log.hpp"



/**
	Exception thrown when a test error occurs.
	
	
	@version	0.1
	@author		<a href="mailto:cant.project@gmail.com">Mikey</a>
*/
class TestCaseException	: public Exception
{
	public:
		/**
			Constructor.
			
			@param		a_strMessage		reason for exception.
		*/
		TestCaseException(const std::string& a_strMessage );
};



//--------------------------------------------------------------------------//



/**
	Base class for test fixtures.
	
	
	@version	0.1
	@author		<a href="mailto:cant.project@gmail.com">Mikey</a>
*/
class TestCase
{
	public:
		/**
			Type of test case method.
			
		*/
		typedef	void (*typeCaseMethod)(TestCase* );
		
		
		/**
			Type of case method list.
			
		*/
		typedef	std::vector<typeCaseMethod>	typeCaseMethodList;

	
	private:
		/**
			List of case methods.
			
		*/
		std::vector<typeCaseMethod>		m_listCaseMethods;
		
		
		/**
			Name of this test case.
			
			@see		getName()
		*/
		std::string						m_strName;
		
	
	public:
		/**
			Constructor.
			
			@param		a_strName		name of test case.
		*/
		TestCase(const std::string& a_strName );
		
		
		/**
			Destructor.
			
		*/
		virtual	~TestCase() throw();
		
		
		/**
			Gives the name of this test case.
			
			@return		test case name.
		*/
		std::string	getName(void ) const;
		
		
		/**
			Gives the number of registered tests.
			
			@return		number of registered tests.
		*/
		int	getCount(void ) const;
		
		
		/**
			Called before each test case's method.
			
		*/
		virtual void	setup(void );
		
		
		/**
			Called after each test case's method.
			
		*/
		virtual void	teardown(void );
		
		
		/**
			Invokes all registered test cases.
			
			@return		number of failed tests.
		*/
		virtual int	run(void );
		
		
		/**
			Pre-condition assertion.
			
			@param		a_bTest			test condition.
			@param		a_strMessage	message to be output on test failure.
		*/
		void	assertPre(bool a_bTest, const std::string a_strMessage ) const;
		
		
		/**
			Post-condition assertion.
			
			@param		a_bTest			test condition.
			@param		a_strMessage	message to be output on test failure.
		*/
		void	assertPost(bool a_bTest, const std::string a_strMessage ) const;
		
		
		/**
			Test assertion.
			
			@param		a_bTest			test condition.
			@param		a_strMessage	message to be output on test failure.
		*/
		void	assertTrue(bool a_bTest, const std::string a_strMessage ) const;
		
		
	protected:
		/**
			Adds a method to be called for a test case.
			
			Note that the method to be added must be <code>static</code>.
			
			@param		a_method		method to be called.
		*/
		void	addMethod(typeCaseMethod a_method );
};

#endif
